//
//  JHMiddleTutorViewController.m
//  JuniRengLish_iOS
//
//  Created by revogi on 2019/5/8.
//  Copyright © 2019 revogi. All rights reserved.
//

#import "JHMiddleTutorViewController.h"
#import "JHMiddleTutorListController.h"
#import "JHMiddenBookModel.h"

@interface JHMiddleTutorViewController ()

// 标题的数组
@property (nonatomic,strong) NSArray *titlesArray;

//图片数组
@property (nonatomic,strong) NSArray *imgesArray;

@property (nonatomic,strong) NSMutableArray *data1Array;  //句型
@property (nonatomic,strong) NSMutableArray *data2Array;  //语法专练
@property (nonatomic,strong) NSMutableArray *data3Array;  //易错题
@property (nonatomic,strong) NSMutableArray *data4Array;  //综合练习
@property (nonatomic,strong) NSMutableArray *data5Array;  //中考作文
@property (nonatomic,strong) NSMutableArray *data6Array;  //重点短句
@property (nonatomic,strong) NSMutableArray *data7Array;  //知识汇总
@property (nonatomic,strong) NSMutableArray *data8Array;  //一词多义
@property (nonatomic,strong) NSMutableArray *data9Array;  //时态

@end

@implementation JHMiddleTutorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title=@"中考辅导";
    [self initNav];
    self.data1Array=[NSMutableArray array];
    self.data2Array=[NSMutableArray array];
    self.data3Array=[NSMutableArray array];
    self.data4Array=[NSMutableArray array];
    self.data5Array=[NSMutableArray array];
    self.data6Array=[NSMutableArray array];
    self.data7Array=[NSMutableArray array];
    self.data8Array=[NSMutableArray array];
    self.data9Array=[NSMutableArray array];
    
    [self getBookInfo];
    
////dddpooeokeofkekfkfkkkfk
    
    //////dddddddddd
    
}

- (void)getBookInfo
{
    NSDictionary *dict=[DJTool readLocalFileWithName:@"BookInfo"];
    
    //句型
    NSArray *item1=dict[@"bookinfo"][0][@"item"];
    self.data1Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item1];
    
    //语法专练
    NSArray *item2=dict[@"bookinfo"][3][@"item"];
    self.data2Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item2];
    //易错题
    NSArray *item3=dict[@"bookinfo"][7][@"item"];
    self.data3Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item3];
    
    //c综合练习
    NSArray *item4=dict[@"bookinfo"][8][@"item"];
    self.data4Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item4];
    //中考作文
    NSArray *item5=dict[@"bookinfo"][5][@"item"];
    self.data5Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item5];
    
    //重点短句
    NSArray *item6=dict[@"bookinfo"][6][@"item"];
    self.data6Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item6];
    
    
    //知识汇总
    NSArray *item7=dict[@"bookinfo"][4][@"item"];
    self.data7Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item7];
    
    
    //一词多义
    NSArray *item8=dict[@"bookinfo"][2][@"item"];
    self.data8Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item8];
    
    //时态
    NSArray *item9=dict[@"bookinfo"][1][@"item"];
    self.data9Array=[JHMiddenBookModel mj_objectArrayWithKeyValuesArray:item9];
    
    
    NSLog(@"%@-------",self.data1Array);
    
}

#pragma mark  --隐藏导航栏

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}


- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)initNav
{
    JHNavView *navView=[[JHNavView alloc]init];
    navView.frame=CGRectMake(0, 0,JKScreenW,170);
    navView.navTitle.text=@"中考辅导";
    [self.view addSubview:navView];
}
- (void)initUI
{
    UIView *btnView=[[UIView alloc]initWithFrame:CGRectMake(0,170,JKScreenW,JKScreenH-170)];
    [self.view addSubview:btnView];
    
    CGFloat BtnW=JKScreenW/3;
    
    UIView *line1View=[[UIView alloc]initWithFrame:CGRectMake(0, BtnW, JKScreenW,0.5)];
    line1View.backgroundColor=[UIColor lightGrayColor];
    [btnView addSubview:line1View];
    
    UIView *line2View=[[UIView alloc]initWithFrame:CGRectMake(0, BtnW *2+0.5, JKScreenW,0.5)];
    line2View.backgroundColor=[UIColor lightGrayColor];
    [btnView addSubview:line2View];
    
    
    UIView *line3View=[[UIView alloc]initWithFrame:CGRectMake(0, BtnW*3+1, JKScreenW,0.5)];
    line3View.backgroundColor=[UIColor lightGrayColor];
    [btnView addSubview:line3View];
    
    UIView *line4View=[[UIView alloc]initWithFrame:CGRectMake(BtnW,0,0.5,BtnW*3+1.5)];
    line4View.backgroundColor=[UIColor lightGrayColor];
    [btnView addSubview:line4View];
    
    
    UIView *line5View=[[UIView alloc]initWithFrame:CGRectMake(BtnW*2+0.5,0,0.5,BtnW*3+1.5)];
    line5View.backgroundColor=[UIColor lightGrayColor];
    [btnView addSubview:line5View];
    
    
    //循环创建n按钮
    
    self.titlesArray=@[@"句型",@"语法专练",@"易错题",@"综合练习",@"中考作文",@"重点短句",@"知识汇总",@"一词多义",@"时态"];
    self.imgesArray=@[@"句型",@"语法专练",@"易错题",@"综合练习",@"中考作文",@"重点短句",@"知识汇总",@"一词多义",@"时态"];
    NSUInteger maxColsCount =3; // 一行的最大列数
    CGFloat buttonW =(JKScreenW-1.5)/ maxColsCount;
    CGFloat buttonH =buttonW;
    for (int index=0;index<self.titlesArray.count;index++ ) {
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.x = (index % maxColsCount) *buttonW;
        btn.y = (index / maxColsCount) *buttonH;
        btn.width=buttonW;
        btn.height=buttonH;
        btn.titleLabel.font=[UIFont systemFontOfSize:14];
        [btn setTitle:self.titlesArray[index] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:self.imgesArray[index]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn layoutButtonWithImageStyle:ZJButtonImageStyleTop imageTitleToSpace:15];
        btn.tag=1000+index;
        [btnView addSubview:btn];
    }
    
}

- (void)btnDidClick:(UIButton *)btn
{
    JHMiddleTutorListController *vc=[[JHMiddleTutorListController alloc]init];
    NSString *navTitle=self.titlesArray[btn.tag-1000];
    if (btn.tag==1000) {
        vc.dataArray=self.data1Array;
    }else if (btn.tag==1001)
    {
        vc.dataArray=self.data2Array;
        
    }else if (btn.tag==1002)
    {
        vc.dataArray=self.data3Array;
        
    }
    else if (btn.tag==1003)
    {
        vc.dataArray=self.data4Array;
        
    }
    else if (btn.tag==1004)
    {
        vc.dataArray=self.data5Array;
        
    }
    else if (btn.tag==1005)
    {
        vc.dataArray=self.data6Array;
        
    }
    else if (btn.tag==1006)
    {
        vc.dataArray=self.data7Array;
        
    }
    else if (btn.tag==1007)
    {
        vc.dataArray=self.data8Array;
        
        
    }else{
        vc.dataArray=self.data9Array;
        
    }
    vc.navTitle=navTitle;
    [self.navigationController pushViewController:vc animated:YES];
    
    
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
